package com.ccjq.shosestore.product.service.impl;

import com.ccjq.shosestore.core.domain.PageInfo;
import com.ccjq.shosestore.core.utils.PageUtils;
import com.ccjq.shosestore.product.dao.HomeDao;
import com.ccjq.shosestore.product.dao.impl.HomeDaoImpl;
import com.ccjq.shosestore.product.po.HomePo;
import com.ccjq.shosestore.product.service.HomeService;
import com.ccjq.shosestore.product.t_productPo.DetailsPo;
import com.ccjq.shosestore.product.t_productPo.productPo;

import java.util.List;

public class HomeServiceImpl implements HomeService {
    HomeDao homedao = new HomeDaoImpl();
    public List<HomePo> selectAll() {
        List<HomePo> HomeList = homedao.selectAll();
        return HomeList;
    }

    public List<productPo> selectNew() {
        List<productPo> homeListNew = homedao.selectNew();
        return homeListNew;
    }

    public List<productPo> selectReMai() {
        List<productPo> homeListReMai = homedao.selectReMai();
        return homeListReMai;
    }

    public int pageCount() {
        int count = homedao.pageCount();
        return count;
    }

    public int pageCountId(String category_id) {
        int count = homedao.pageCountId(category_id);
        return count;
    }

    public PageInfo<productPo> selectFengYeAll(int pageSize, int pageNo) {

        int startRow = PageUtils.getStartRow(pageSize, pageNo);
        List<productPo> listAll = homedao.selectFengYeAll(startRow,pageSize);
        int total = homedao.pageCount();
        int pages = PageUtils.getPageCount(total, pageSize);

        PageInfo<productPo> pageInfo = new PageInfo<productPo>();
        pageInfo.setPageNo(pageNo);
        pageInfo.setPageSize(pageSize);
        pageInfo.setPages(pages);
        pageInfo.setTotal(total);
        pageInfo.setObjs(listAll);
        return pageInfo;
    }

    public PageInfo<productPo> selectFengYe(String category_id, int pageSize, int pageNo) {

        int startRow = PageUtils.getStartRow(pageSize,pageNo);//获取当前行
        int pageSizes = (pageSize+startRow)-1;//要显示的行数
        List<productPo> listAll = homedao.selectFengYe(category_id, startRow,pageSizes);//获取分页的数据
        int total = homedao.pageCountId(category_id);//计算总行数
        int pages = PageUtils.getPageCount(total, pageSize);//获取总页数

        PageInfo<productPo> pageInfo = new PageInfo<productPo>();
        pageInfo.setPageNo(pageNo);
        pageInfo.setPageSize(pageSize);
        pageInfo.setPages(pages);
        pageInfo.setTotal(total);
        pageInfo.setObjs(listAll);
        return pageInfo;
    }

    public DetailsPo selectDatails(String product_id) {
        DetailsPo detailsPo = homedao.selectDatails(product_id);
        return detailsPo;
    }
}
